<?php

class Model_image extends CI_Model {
    
    function __construct() {
        parent::__construct();
    }

    public function getImage($id) {
        $collection = $this->mongo_db->db->selectCollection('image');
        $image = $collection->find(array('_id'=> $id));      
        return $image;
    }

/**
 * ============================UPDATE IMAGE=============================================
*/
    public function update_info($id_img, $time, $description, $lesson){
        $collection = $this->mongo_db->db->selectCollection('image');
        $data = array(
            '_id' =>$id_img,
            'time' => $time,
            'description' => $description,
            'lesson' => $lesson
            );
        $collection->update(array('_id' => new MongoId($id_img)), $data);
    }
/**
 * ============================DELETE IMAGE =============================================
*/
    public function delete_image($id_img){
        $collection = $this->mongo_db->db->selectCollection('image');
        $collection->remove(array('_id' => new MongoId($id_img)));
    }

//===============================INSERT NEW IMAGE=============================================
    public function insert_image($id_img, $time, $description, $lesson)
    {
        $collection = $this->mongo_db->db->selectCollection('image');
        $data = array(
            '_id' =>$id_img,
            'time' => $time,
            'description' => $description,
            'lesson' => $lesson
            );
        $collection->insert($data);
    }
}
?>